package com.jsoft.jsofted.framework.utils;

import lombok.Data;

@Data
public class ResponseModel {

    private boolean success;
    private int errorCode;
    private String message;
    private Object data;

    public static ResponseModel makeSuccess() {
        return makeSuccess("");
    }

    public static ResponseModel makeSuccess(String message) {
        return makeSuccess(message, null);
    }

    public static ResponseModel makeSuccess(Object data) {
        return makeSuccess(null, data);
    }

    public static ResponseModel makeSuccess(String message, Object data) {
        ResponseModel model = new ResponseModel();

        model.setSuccess(true);
        model.setMessage((message == null || message.trim().length() == 0) ? "操作成功！" : message);
        model.setData(data);

        return model;
    }

    public static ResponseModel makeError(String message, int errorCode, Object data) {
        ResponseModel model = new ResponseModel();

        model.setSuccess(false);
        model.setErrorCode(errorCode);
        model.setMessage((message == null || message.trim().length() == 0) ? "操作失败！" : message);
        model.setData(data);

        return model;
    }

    public static ResponseModel makeError(String message, int errorCode) {
        return ResponseModel.makeError(message, errorCode, null);
    }

    public static ResponseModel makeError() {
        return makeError("");
    }

    public static ResponseModel makeError(String message) {
        return ResponseModel.makeError(message, 0, null);
    }

    @Override
    public String toString() {
        return "ResponseModel{" +
                "success=" + success +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
